All Questions
99 questions
4votes
4answers
507views
Finding Special Parts in a Word
Task description: Imagine you have a long word made up of small letters like "a", "b", "c", ancd so on. Let’s call this word a puzzle word. We want to look at all the ...
2votes
2answers
866views
Counting uppercase and lowercase characters in a string
I created two programs (one with JAVA8) to calculate the total count of uppercase and lowercase characters in given String. After checking the execution time JAVA8 is taking longer execution time than ...
9votes
1answer
1kviews
Generate unique random strings considering collisions
I'm coding a random strings generator. It's working, but I'm not sure if this is efficient. ...
3votes
3answers
160views
Java regex and replaceAll to extract strings into objects
I have this method that creates book objects. I pass a list of strings (size 60000+) that contain the information of the book, the function then goes and extracts the information makes the book object ...
3votes
1answer
254views
Knuth-Morris-Pratt algorithm in Java Finding substrings in a matrix
Problem Given two matrices: a pattern p and a text t. Write a program that counts the number of occurrences of ...
3votes
1answer
184views
Left or right padding a string with the specified character
Can I improve performance of below method? Is there anything I need to optimize or any redundancy I need to remove to make it more efficient? It's a simple method used to pad strings by left or right. ...
1vote
2answers
290views
Optimize printing massive strings to System.out with respect to time
I need to cut the time it takes to print a large string by ~50%. I went from using s1 + s2 to using StringBuilder, and instead ...
5votes
2answers
1kviews
Find hamming distance between two Strings of equal length in Java
I have a private class that I want to be able to find the shortest Hamming Distance between two Strings of equal length in Java. The private class holds a char[] ...
2votes
1answer
229views
String reversing x times
Inspired by CodeWars We have a string s Let's say you start with this: "String" The first thing you do is reverse it: "gnirtS" Then you will take ...
0votes
1answer
2kviews
Parsing messages with fixed-width fields into Employee objects
I'm writing a application that reads from a queue of messages from a legacy mainframe system. Some characteristics of message in the queue: Message from the Q is always fixed length plain text : 64 ...
3votes
1answer
251views
Map Character to Characters Most Frequently Found With it (in list of strings)
For an interview, I was tasked with writing a program that consumes a list of strings, and produces a mapping between every character in the list, and the characters found most frequently with it (let'...
2votes
4answers
900views
Split a string into a list of tokens
I have the following assignment that I succeeded in solving, but the code is very inefficient. I would appreciate if someone could show me a more efficient way, perhaps with substring. Note that I am ...
2votes
2answers
69views
Longest substring with 2 unique characters in a given string at linear time
This is my java implementation based on the solution of Aasmund Eldhuset here. Please give your opinion on my code (correctness, efficiency and coding conventions): ...
2votes
1answer
1kviews
Random string generation in Java
Can random string generation be faster in Java? Here is my current code ...
2votes
2answers
97views
Method that receives a hexadecimal string and returns a formatted matrix of those values
This method is part of a larger project and comes after encoding ascii characters into hexadecimal values, so it assumes the parameter is always a valid hex string. ...